package com.ems.service.impl.supers.questions;

import com.ems.dao.supers.questions.FillDao;
import com.ems.dao.supers.questions.answer.FillAnswerDao;
import com.ems.pojo.data.RequestData;
import com.ems.pojo.questions.FillBanks;
import com.ems.pojo.questions.Subject;
import com.ems.pojo.questions.answer.FillBanksAnswer;
import com.ems.service.supers.questions.FillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: 伟伟
 * @Date: 2019/10/29
 * @Description: 描述
 * @Version: 1.0
 */
@Service("fillService")
public class FillServiceImpl implements FillService {

    @Autowired
    private FillDao fillDao;

    @Autowired
    private FillAnswerDao fillAnswerDao;

    private FillBanksAnswer fillBanksAnswer;

    private FillBanks fillBanks;

    /**
     * 添加填空题
     * @param fillBanksList
     */
    @Override
    public void addFill(List<FillBanks> fillBanksList) {
        if(fillBanksList != null){
            for(int i = 0;i < fillBanksList.size();i ++){
                fillBanks = fillBanksList.get(i);
                fillDao.addFill(fillBanks);
                fillBanksAnswer = fillBanks.getFillBanksAnswer();
                fillBanksAnswer.setFb_id(fillBanks.getFb_id());
                fillAnswerDao.addFillAnswer(fillBanksAnswer);
            }
        }
    }

    @Override
    public void deleteFill(List<FillBanks> fillBanksList) {
       for(int i = 0;i < fillBanksList.size();i ++){
           fillAnswerDao.deleteFillAnswer(fillBanksList.get(i).getFillBanksAnswer());
           fillDao.deleteFill(fillBanksList.get(i));
       }
    }

    @Override
    public void updateFill(FillBanks fillBanks) {
        fillDao.updateFill(fillBanks);
        fillAnswerDao.updateFillAnswer(fillBanks.getFillBanksAnswer());
    }

    @Override
    public List<Subject> findFill(RequestData requestData) {
         List<Subject> list = fillDao.findFill(requestData.getMap());
         return list;
    }

    //获取判断题的数量
    @Override
    public int getFillCount() {
        return fillDao.getFillCount();
    }

    @Override
    public List<FillBanks> getFillBanksBySbAndId(int sb_id, int num) {
        return fillDao.getFillBanksBySbAndId(sb_id,num);
    }

    //根据id集合查询填空题
    @Override
    public List<FillBanks> getFillBanksByIdsList(List<Integer> idsList) {
        return fillDao.getFillBanksByIdsList(idsList);
    }

    @Override
    public FillBanksAnswer getAnswer(int id) {
        return fillAnswerDao.getAnswer(id);
    }
}
